home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / utils / graphic / viewers / jpeg / msdos / dvpeg / src1b / dvsetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-09  |  12.2 KB  |  397 lines

  1. /*
  2. /* let the user test and pick video modes */
  3. /*                                        */
  4. /* text screen is: a title on the top line
  5.                          a video card list (columns 1 to 24)
  6.                          a video mode list in the upper right corner (rows 2 to 12)
  7.                          a selected mode list in the lower right (rows 13 to 24)
  8.         --> if the lists ever exceed the ranges scroll bars will have to be added
  9.  
  10.   problems
  11.   - plotting border has problems on the last char because it causes a CR/LF !!
  12.   - loading the mask string needs a \n termination but this will be added the next time its
  13.         saved (ie you have 2 then 3 then 4 ...  -> so search the string and clip them out - done during loadin
  14. */
  15.  
  16. #include "jvsetup.h"
  17. #include "conio.h"
  18. #include "stdio.h"
  19.  
  20.  
  21. extern unsigned _stklen = 8192;
  22.  
  23.  
  24. int get_key(void);
  25. void borders(int hi_light);
  26. void test_video(int sel_card, int sel_mode);
  27.  
  28.  
  29. /* get a key and strip that pesky 0 if its a usefull {arrow, page, insert, delete ..} key */
  30.  
  31. int get_key(void)
  32. {
  33. int cmd;
  34. if ( (cmd = getch()) == 0) cmd = getch();
  35. return cmd;
  36. }
  37.  
  38.  
  39. /* draw the dividers on the screen for the text mode video selection
  40.      hi_light is the flag to draw a bright border around (active area)
  41.   */
  42.  
  43. void test_video(int sel_card, int sel_mode)
  44. {
  45. static int i,
  46.             x, y,
  47.             x_size,
  48.             y_size;
  49.  
  50. x_size = video_cards[sel_card].vid_mode[sel_mode].x_size;
  51. y_size = video_cards[sel_card].vid_mode[sel_mode].y_size;
  52.  
  53. forcevga(sel_card);
  54. svgamode(video_cards[sel_card].vid_mode[sel_mode].mode_number, x_size);
  55.  
  56. if (hi_color == 0){
  57.     for (i=0; i<256; i++){
  58.         palbuf[i][0] = 64 - i / 4;
  59.         palbuf[i][1] = (i / 2) % 64;
  60.         palbuf[i][2] = i % 64;
  61.         }
  62.     setmany(palbuf,0,256);
  63.     }
  64. for (x=0; x < x_size; x++)
  65.     for(y=0; y < y_size; y++)
  66.         if (hi_color)
  67.             if (sel_card == 16){        /* ATI hi_color card */
  68.                 point(2*x,y, palbuf[x%256][2] + (palbuf[x%256][1]<<5));
  69.                 point(2*x+1,y, (palbuf[x%256][1] << 5) + (palbuf[x%256][0] << 10));
  70.                 }
  71.             else
  72.                 point_hi(x,y, palbuf[x%256][2]+(palbuf[x%256][1]<<5) + (palbuf[x%256][0] << 10));
  73.         else
  74.             point(x,y,x%256);
  75. getch();
  76. textmode(C80);
  77. }
  78.  
  79.  
  80. void borders(int hi_light)
  81. {
  82. int i;
  83. char char_is;
  84. struct text_info ti;
  85.  
  86. gettextinfo(&ti);
  87.  
  88. if (hi_light){
  89.     textcolor(WHITE);
  90.     char_is = 219;            /* solid block */
  91.     }
  92. else{
  93.     textcolor(LIGHTGRAY);
  94.     char_is = 177;            /* 1/2 dense block */
  95.     }
  96.  
  97. for (i=1; i <= (ti.winright-ti.winleft); i++){        /* should go 1 count more */
  98.     gotoxy(i, 1);
  99.     putch(char_is);
  100.     gotoxy(i, ti.winbottom - ti.wintop + 1);
  101.     putch(char_is);
  102.     }
  103. for (i=2; i <= (ti.winbottom-ti.wintop); i++){
  104.     gotoxy(1, i);
  105.     putch(char_is);
  106.     gotoxy(ti.winright - ti.winleft, i);        /* had to sub +1 */
  107.     putch(char_is);
  108.     }
  109. }
  110.  
  111.  
  112. int main(void)
  113. {
  114. static int i,
  115.             exit_now,            /* exit flag for main loop */
  116.             sel_card,            /* pointer into array for selected video card */
  117.             sel_mode,            /* pointer into array for selected mode */
  118.             sel_mode_list,        /* currently item in selected mode list pointed to */
  119.             ins_loc,                /* location to insert a new item into the users list of working modes */
  120.             some,                    /* a check to make sure that the user mode list is not empty - otherwise the prog locs! */
  121.             update_file,        /* flag that cfg info has change */
  122.             text_width,            /* text screen width - currently 80 char - not yet used*/
  123.             text_mode,            /* mode for the text screen - not yet used */
  124.             sort_mode,            /* method to sort file list by - not yet used*/
  125.             card_mode_oklist;        /* flag for oklist (0) or card (2) or mode (1) in selection*/
  126. static char cmd;
  127. static struct text_info ti;
  128. static char file_mask[20] = "*.*";
  129.             FILE *config_file;
  130.  
  131. for (i = 0; i <= number_modes_in_list; i++)
  132.     ok_mode[i].card_ID = -1;                    /* set to not filled */
  133.  
  134.  
  135. /* does the dvpeg.cfg file exist? */
  136. config_file = fopen("dvpeg.cfg", "rb");
  137. if (config_file != NULL){                        /* load the file mode descriptions */
  138.     text_width = getw(config_file);
  139.     text_mode = getw(config_file);
  140.     sort_mode = getw(config_file);
  141.     fgets(file_mask, 15, config_file);
  142.     for (i=0; i < 15; i++)
  143.         if (file_mask[i] == '\n') file_mask[i] = 0;        /* remove that \n since it is only needed for loading string in */
  144.     i = 0;
  145.     while((sel_card = getw(config_file)) != -1){
  146.         if (i >= number_modes_in_list){
  147.             printf("Configuration file is in error.  Please delete it.\r\n");
  148.             exit(-1);
  149.             }
  150.         ok_mode[i].card_ID = sel_card;
  151.         ok_mode[i++].which_mode = getw(config_file);
  152.         card_id = sel_card;        /* let the menu default to last card in the list */
  153.         }
  154.     fclose(config_file);
  155.     }
  156. else{                    /* no? then autodetect */
  157.     svga=whichvga();
  158.     if (svga){
  159.         if (aheada == 1 || aheadb == 1) card_id = 0;
  160.         if (ativga == 1) card_id = 1;
  161.         if (chipstech == 1) card_id = 2;
  162.         if (everex == 1) card_id = 3;
  163.         if (oaktech == 1) card_id = 4;
  164.         if (genoa == 1) card_id = 5;
  165.         if (ncr == 1) card_id = 6;
  166.         if (paradise == 1) card_id = 7;
  167.         if (trident == 1)
  168.         if (t8900 == 1) card_id = 9;
  169.             else card_id = 8;
  170.         if (tseng == 1)
  171.             if (tseng4 == 1) card_id = 11;
  172.             else card_id = 10;
  173.         if (video7 == 1) card_id = 12;
  174.         if (cirrus == 1) card_id = 13;
  175.         if (compaq == 1) card_id = 14;
  176.         if (vesa == 1) card_id = 15;
  177.  
  178.         /* assume all modes are there and copy them over */
  179.         for (i=0; i < number_modes_supported; i++)
  180.             if (video_cards[card_id].vid_mode[i].mode_number != 0){
  181.                 ok_mode[i].card_ID = card_id;
  182.                 ok_mode[i].which_mode = i;
  183.                 }
  184.         update_file = 1;
  185.         }
  186.     else
  187.         {
  188.         card_id = 0;                /* let the user guess what it is but assume 320 * 200 mode (first in all of them) */
  189.         ok_mode[0].card_ID = 0;        /* make sure that there is one item in the selected list */
  190.         ok_mode[0].which_mode = 0;          /*  this will always be 320 * 200 */
  191.         }
  192.     }
  193.  
  194.  
  195. sel_card = card_id;
  196. sel_mode = sel_mode_list = 0;            /* default to lowest resolution, card detected*/
  197.  
  198. textmode(C80);
  199. _setcursortype(_NOCURSOR);            /* hide the cursor*/
  200.  
  201. gettextinfo(&ti);
  202.  
  203. card_mode_oklist = 2;        /* start with card menu*/
  204.  
  205. /* select a video card and mode */
  206. clrscr();
  207. textcolor(YELLOW);
  208. gotoxy(1,1);
  209. cprintf("             Video Setup                                          Dvpeg");
  210.  
  211. /* note right side has to be wider to prevent CR/LF on plotting char 1! */
  212.  
  213. do{
  214.     window(1, 2, 24, 25);
  215. /* setup the borders on the screen with video card hi_light */
  216.     borders(card_mode_oklist == 2);
  217.     window(2, 3, 23, 24);
  218.     gotoxy(1,1);
  219.     textcolor(YELLOW);
  220.     cprintf("  Video cards\n\r");
  221.     textcolor(WHITE);
  222.     for (i=0; i < number_VGA_cards; i++){
  223.         if (i == sel_card)
  224.             if (card_mode_oklist == 2)    textcolor(LIGHTMAGENTA);
  225.             else    textcolor(MAGENTA);
  226.             cprintf("  %2i - %s\r\n", i, video_cards[i].name);
  227.         textcolor(WHITE);
  228.         }
  229.  
  230.     window(25, 2, 80, 11);        /* plot video mode available */
  231.     borders(card_mode_oklist == 1);
  232.     window(26, 3, 78, 10);
  233.     clrscr();
  234.     gotoxy(1,1);
  235.     textcolor(YELLOW);
  236.     cprintf("   Video Modes\r\n");
  237.     textcolor(WHITE);
  238.     cprintf(" X size, Y size, mode #\n\r");
  239.     for (i=0; i < number_modes_supported; i++)
  240.         if (video_cards[sel_card].vid_mode[i].mode_number != 0){
  241.             if (i == sel_mode)
  242.                 if (card_mode_oklist == 1)    textcolor(LIGHTMAGENTA);
  243.                 else    textcolor(MAGENTA);
  244.             cprintf(" %4i   %5i   %4hu\r\n",video_cards[sel_card].vid_mode[i].x_size,video_cards[sel_card].vid_mode[i].y_size, video_cards[sel_card].vid_mode[i].mode_number);
  245.             textcolor(WHITE);
  246.             }
  247.  
  248.     window(25, 12, 80, 25);        /* plot video mode list as selected */
  249.     borders(card_mode_oklist == 0);
  250.     window(26, 13, 78, 24);
  251.     clrscr();
  252.     gotoxy(1,1);
  253.     textcolor(YELLOW);
  254.     cprintf("         Selected Video Modes\n\r");
  255.     textcolor(WHITE);
  256.     cprintf(" Video Card,        X size, Y size, mode #\n\r");
  257.     for (i=0; i < number_modes_in_list; i++)
  258.         if (ok_mode[i].card_ID >= 0){
  259.             if (i == sel_mode_list)
  260.                 if (card_mode_oklist == 0)    textcolor(LIGHTMAGENTA);
  261.                 else    textcolor(MAGENTA);
  262.             cprintf(" %15s    %4i   %5i   %4hu\r\n",video_cards[ok_mode[i].card_ID].name,
  263.                 video_cards[ok_mode[i].card_ID].vid_mode[ok_mode[i].which_mode].x_size,video_cards[ok_mode[i].card_ID].vid_mode[ok_mode[i].which_mode].y_size, video_cards[ok_mode[i].card_ID].vid_mode[ok_mode[i].which_mode].mode_number);
  264.             textcolor(WHITE);
  265.             }
  266.  
  267.     cmd = get_key();
  268.     if (cmd == escape){
  269.         if (card_mode_oklist == 2) exit_now = 1;
  270.         else card_mode_oklist++;                    /* RTN selects mode and/or exit */
  271.         cmd = 0;
  272.         }
  273.     if (cmd == RTN){
  274.         card_mode_oklist--;        /* ESC hops to card select */
  275.         cmd = 0;                        /* only change menu, don't act on cmd */
  276.         }
  277.     if (card_mode_oklist < 0) card_mode_oklist = 0;
  278.     switch (card_mode_oklist){
  279.         case 0:            /* ok mode list ie select for delete */
  280.             for (some = 0, i=0; i< number_modes_in_list; i++)        /* check for an empty list which would hang the S/W */
  281.                 if (ok_mode[i].card_ID >= 0)
  282.                     some = 1;
  283.  
  284.             switch (cmd){
  285.                 case arrow_up:
  286.                     do{
  287.                         if (sel_mode_list > 0) sel_mode_list -=1;
  288.                         else sel_mode_list = number_modes_in_list - 1;
  289.                         } while (ok_mode[sel_mode_list].card_ID < 0 && some);
  290.                     break;
  291.                 case arrow_down:
  292.                     do{
  293.                         if (sel_mode_list < number_modes_in_list-1) sel_mode_list += 1;
  294.                         else sel_mode_list = 0;
  295.                         } while (ok_mode[sel_mode_list].card_ID < 0 && some);
  296.                     break;
  297.                 case delete:
  298.                     for (i=sel_mode_list; i < number_modes_in_list; i++){
  299.                         ok_mode[i].card_ID = ok_mode[i+1].card_ID;
  300.                         ok_mode[i].which_mode = ok_mode[i+1].which_mode;
  301.                         }
  302.                     update_file = 1;
  303.                     sel_mode = sel_mode_list = 0;        /* reset so point points to something */
  304.                     break;
  305.                 }
  306.                 break;
  307.         case 2:            /* select a video card move up/down */
  308.             switch (cmd){
  309.                 case arrow_up:
  310.                     if (sel_card > 0) sel_card -=1;
  311.                     else sel_card = number_VGA_cards - 1;
  312.                     sel_mode = 0;        /* old mode number may be high so reset */
  313.                     break;
  314.                 case arrow_down:
  315.                     if (sel_card < number_VGA_cards - 1) sel_card += 1;
  316.                     else sel_card = 0;
  317.                     sel_mode = 0;
  318.                 }
  319.                 break;
  320.         case 1:            /* select a video mode -> test/add to list */
  321.             switch (cmd){
  322.                 case arrow_up:
  323.                     do{                /* make sure that we get an existing mode */
  324.                         if (sel_mode > 0) sel_mode -=1;
  325.                         else sel_mode = number_modes_supported - 1;
  326.                         } while (video_cards[sel_card].vid_mode[sel_mode].mode_number == 0);
  327.                     break;
  328.                 case arrow_down:
  329.                     do{
  330.                         if (sel_mode < number_modes_supported - 1) sel_mode += 1;
  331.                         else sel_mode = 0;
  332.                         } while (video_cards[sel_card].vid_mode[sel_mode].mode_number == 0);
  333.                     break;
  334.                 case insert:
  335.                     ins_loc = 0;
  336.                     /* first find the position of a mode that is non 0 and lower resolution than the selected */
  337.                     for (i = 0; i < number_modes_in_list; i++)
  338.                         if (ok_mode[i].card_ID >= 0)
  339.                             if ((video_cards[ok_mode[i].card_ID].vid_mode[ok_mode[i].which_mode].y_size <
  340.                                     video_cards[sel_card].vid_mode[sel_mode].y_size) &&
  341.                                     ( video_cards[sel_card].vid_mode[sel_mode].y_size != 0))
  342.                                 ins_loc = i + 1;
  343.  
  344.                         /* inserting to a full list does nothing */
  345.                         i = number_modes_in_list;
  346.                         while( --i > ins_loc){
  347.                             ok_mode[i].card_ID = ok_mode[i-1].card_ID;
  348.                             ok_mode[i].which_mode = ok_mode[i-1].which_mode;
  349.                             }
  350.  
  351.                         /* now insert it - watchout for inserting at top + 1*/
  352.                         if (ins_loc < number_modes_in_list){
  353.                             ok_mode[ins_loc].card_ID = sel_card;
  354.                             ok_mode[ins_loc].which_mode = sel_mode;
  355.                             }
  356.                     update_file = 1;
  357.                     break;
  358.                 case 0:
  359.                     break;        /* make sure return, esc does nothing */
  360.                 default:            /* default to testing the mode */
  361.                     test_video(sel_card, sel_mode);
  362.             }
  363.             break;
  364.         }
  365.     } while (exit_now == 0);
  366.  
  367. textmode(C80);
  368. clrscr();
  369. _setcursortype(_NORMALCURSOR);
  370.  
  371. if (update_file){            /* file was changed - does the user want to save it? */
  372.     printf("The video information has changed.\n\r");
  373.     printf("Do you want to save it (Y or N)?\n\r");
  374.     cmd = toupper(getch());
  375.     if (cmd == 'Y'){
  376.         config_file = fopen("dvpeg.cfg","wb");
  377.         if (config_file != NULL){                        /* load the file mode descriptions */
  378.             putw(text_width, config_file);
  379.             putw(text_mode, config_file);
  380.             putw(sort_mode, config_file);
  381.             fputs(file_mask, config_file);
  382.             fputs("\n", config_file);
  383.             i = 0;
  384.             do{
  385.                 putw(ok_mode[i].card_ID, config_file);
  386.                 putw(ok_mode[i].which_mode, config_file);
  387.                 } while(ok_mode[i++].card_ID != -1);
  388.  
  389.             fclose(config_file);
  390.             }
  391.         else
  392.             printf("Error saving the file.\r\n");
  393.         }
  394.     }
  395. return(0);
  396. }    /* main */
  397.